//
//  MyDataService.m
//  HaveMonkey
//
//  Created by hunuo on 15/12/4.
//  Copyright © 2015年 hunuo. All rights reserved.
//

#import "MyDataService.h"

@implementation MyDataService
+(AFHTTPRequestOperation *)requestURL:(NSString *)url  parameters:(NSDictionary *)pareames complete:(CompleteBlock)block {
    
    AFHTTPRequestOperation *operation = nil; // 这个没有实际作用，返回类型可写成void
    //1.管理器
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
//    [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    
    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
    
    //2.设置登录参数
    NSString*infoStr11=[NSString stringWithFormat:@"/oauth/token?username=18888888888&password=123456&grant_type=password&scope=read%%20write&client_secret=6a30d51a3330b85a0fa738a1a88cfcc4&client_id=k_songapp"];
                        
    NSString *intactURL = [MyBaseUrl stringByAppendingString:infoStr11];
    
    NSLog(@"intactURL:%@",intactURL);
    //3.请求
    
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    [manager GET:intactURL parameters:pareames success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        //自动返回主线程
        block(responseObject);
                
        
    } failure: ^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"%@", error);
        
    }];
    return operation;
    
}

@end
